home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr50 / mlibv22.zip / CVT2DATA.BAS next >
BASIC Source File  |  1993-01-27  |  11KB  |  238 lines

  1. DEFINT A-Z
  2. '****************************** CVT2DATA.BAS ********************************
  3. '*                                                                          *
  4. '* This example will:Convert binary data in a [????.SHP] to DATA statements *
  5. '*                  :which can then be compiled with your program.          *
  6. '*                                                                          *
  7. '* NOTE: In order for this demo to run you must start the QB editor         *
  8. '*     : along with the library MLIBN.QLB  (ie., QB/L MLIBN).               *
  9. '*     :                                                                    *
  10. '*     : IF YOU ARE NOT USING QuickBASIC 4.0- 4.5 SEE PAGE 2 OF THE MANUAL  *
  11. '*     : BEFORE TRYING TO RUN THIS PROGRAM!                                 *
  12. '*     :                                                                    *
  13. '*     : The first record (or 80 bytes) of each shape file is the header;   *
  14. '*     : it is of importance only to the mouse editor (which is included    *
  15. '*     : with the registered version).                                      *
  16. '*     :                                                                    *
  17. '*                                                                          *
  18. '****************************************************************************
  19.  
  20. '$INCLUDE: 'mlib.inc'
  21.  
  22. DECLARE SUB ReadData ()
  23. DECLARE SUB Target ()
  24. DECLARE SUB GetInput (SHP$, DAT$, RNum%)
  25. DECLARE SUB Cvt2Data (SHP$, DAT$, RNum%)
  26.  
  27. '============================================================================
  28.                                                  '
  29. SCREEN 12: CLS : CALL InitPointer(NumBut%)       '
  30.                                                  '
  31. IF NumBut% = 0 THEN SCREEN 0: END                'No mouse.
  32.                                                  '
  33. CALL GetInput(SHP$, DAT$, RNum%)                 'User input.
  34.                                                  '
  35. CALL Cvt2Data(SHP$, DAT$, RNum%)                 'Convert to DATA statements.
  36.                                                  '
  37. CALL ReadData                                    'Convert DATA into a shape.
  38.                                                  '
  39. CLS : CALL Target                                'Draw a background.
  40.                                                  '
  41. PRINT "  <DATA created pointer shape shown.>";   '
  42.                                                  '
  43. PRINT "                <Press a key to end.>"    '
  44.                                                  '
  45. CALL ShowPointer                                 '
  46.                                                  '
  47. DO: LOOP UNTIL LEN(INKEY$)                       '
  48.                                                  '
  49. SCREEN 0: END                                    '
  50.                                                  '
  51. '============================================================================
  52.  
  53. '=======================< Example output of this program >===================
  54.  
  55. 'The first 2 data constants (in each block) contain the hotspot x,y values.
  56. 'You must cut and paste your own to display other shapes.
  57. 'Just run this demo, next ALT+F+L oad DATA filename, cut and paste it here.
  58. 'Subroutine ReadData converts this DATA back into a pointer shape.
  59.  
  60. 'Arrow pointer, in SOLID format.
  61. 'REMing this DATA block = TRANS.
  62.  
  63. 'Source      : DEMO.SHP
  64. 'Destination : DATA.DAT
  65. 'Record      : 1
  66. 'Format      : SOLID
  67. DATA &H0,&H0,&H3FFD,&HFFA,&H3FB,&HFA,&H3D,&HF,&H3
  68. DATA &H1,&H3F,&H81F,&H1C0F,&H3E07,&H7F03,&HFF83,&HFFC7,&HFFFF
  69. DATA &H0,&H4000,&H7000,&H7C00,&H7F00,&H7FC0,&H7FF0,&H7F00,&H6780
  70. DATA &H43C0,&H1E0,&HF0,&H78,&H38,&H0,&H0
  71.  
  72.  
  73. 'Arrow pointer, in TRANSparent format.
  74.  
  75. 'Source      : DEMO.SHP
  76. 'Destination : DATA.DAT
  77. 'Record      : 19
  78. 'Format      : TRANS
  79. DATA &H0,&H0,&HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF
  80. DATA &HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF
  81. DATA &HC002,&HF005,&HFC04,&HFF05,&HFFC2,&HFFF0,&HFFFC,&HFFFE,&HFFC0
  82. DATA &HF7E0,&HE3F0,&HC1F8,&H80FC,&H7C,&H38,&H0
  83.  
  84. '============================================================================
  85.  
  86. SUB Cvt2Data (SHP$, DAT$, RNum%)
  87.  
  88. FH1% = FREEFILE: OPEN SHP$ FOR BINARY AS #FH1%   '
  89. FH2% = FREEFILE: OPEN DAT$ FOR OUTPUT AS #FH2%   'Sequential output.
  90. EndData% = RNum% * 80 - 1                        'Calculate end of data, work
  91. StartData% = EndData% - 62                       'backwards.Why? Because.
  92. Xoff% = StartData% - 14                          'Hot spot X offset.
  93. Yoff% = Xoff% + 2                                'Hot spot Y offset.
  94.                                                  '
  95. DIM Format AS STRING * 10: CLS                     '
  96.                                                  '
  97. RNum% = RNum% - 1                                'Get actual record.
  98. GET #FH1%, Xoff%, HotX%                          'Get the hotspots.
  99. GET #FH1%, Yoff%, HotY%                          '
  100. GET #FH1%, Yoff% + 2, Format                     'Solid or Transparent shape.
  101.                                                  '
  102. PRINT #FH2%, "'Source      : "; SHP$             'Print to file.
  103. PRINT #FH2%, "'Destination : "; DAT$
  104. PRINT #FH2%, "'Record      :"; RNum%
  105. PRINT #FH2%, "'Format      : "; Format
  106. PRINT #FH2%, "DATA "; "&H"; HEX$(HotX%); ","; "&H"; HEX$(HotY%);
  107.  
  108. PRINT "'Source      : "; SHP$                    'Print to screen.
  109. PRINT "'Destination : "; DAT$
  110. PRINT "'Record      :"; RNum%
  111. PRINT "'Format      : "; Format
  112. PRINT "DATA "; "&H"; HEX$(HotX%); ","; "&H"; HEX$(HotY%);
  113. Cntr% = 2
  114.  
  115. FOR OffSet% = StartData% TO EndData% STEP 2      '64 bytes.
  116.  
  117.   Cntr% = Cntr% + 1
  118.   GET #FH1%, OffSet%, Get2Byte%
  119.   SHPDAT$ = SHPDAT$ + MKI$(Get2Byte%)
  120.  
  121.   SELECT CASE Cntr%
  122.      CASE IS = 1
  123.         PRINT #FH2%, "DATA "; "&H"; HEX$(Get2Byte%);
  124.         PRINT "DATA "; "&H"; HEX$(Get2Byte%);
  125.      CASE IS <= 8
  126.         PRINT #FH2%, ","; ; "&H"; HEX$(Get2Byte%);
  127.         PRINT ","; "&H"; HEX$(Get2Byte%);
  128.      CASE IS > 8
  129.         PRINT #FH2%, ","; ; "&H"; HEX$(Get2Byte%)
  130.         PRINT ","; "&H"; HEX$(Get2Byte%)
  131.         Cntr% = 0
  132.   END SELECT
  133.  
  134. NEXT OffSet%
  135.  
  136. CLOSE
  137. PRINT : PRINT : PRINT "Converted pointer shape shown."
  138. PRINT : PRINT : PRINT "Press a key to continue."
  139.  
  140. ShowPointer                                      'Show the shape that was
  141. CALL ChangePointer(SHPDAT$, HotX%, HotY%)        'just converted to DATA
  142. Hold$ = INPUT$(1): HidePointer                   'statements.
  143.  
  144. END SUB
  145.  
  146. SUB GetInput (SHP$, DAT$, RNum%)
  147.  
  148. TryAgain1:
  149.  
  150. PRINT "               ┌───────────────────────────────────────────────────┐"
  151. PRINT "               │                                                   │"
  152. PRINT "               │       Source: Name of the [XXX.SHP] file that     │"
  153. PRINT "               │               contains the shape information      │"
  154. PRINT "               │               to convert to DATA statements.      │"
  155. PRINT "               │                                                   │"
  156. PRINT "               │               NOTE! You must supply the complete  │"
  157. PRINT "               │               filename.                           │"
  158. PRINT "               │                                                   │"
  159. PRINT "               │  Destination: Name of the output file that will   │"
  160. PRINT "               │               hold the DATA statements.           │"
  161. PRINT "               │                                                   │"
  162. PRINT "               │                                                   │"
  163. PRINT "               │ Shape number: Number of the desired shape.        │"
  164. PRINT "               │               (Run VIEWSHP.BAS to get number)     │"
  165. PRINT "               │                                                   │"
  166. PRINT "               └───────────────────────────────────────────────────┘"
  167.  
  168.  
  169. INPUT "Source       <ENTER=[DEMO.SHP]> : "; SHP$ 'File to open.
  170. INPUT "Destination  <ENTER=[DATA.DAT]> : "; DAT$ 'Data output file.
  171.                                                  '
  172. IF LEN(SHP$) = 0 THEN SHP$ = "DEMO.SHP"          '
  173. IF LEN(DAT$) = 0 THEN DAT$ = "DATA.DAT"          '
  174.                                                  '
  175. FH% = FREEFILE                                   '
  176. OPEN SHP$ FOR INPUT AS #FH%                      '
  177.                                                  '
  178. MaxRec% = (LOF(FH%) \ 80) - 1: CLOSE             'Calculate number of records,
  179.                                                  'minus 1, header not counted.
  180. TryAgain:                                        '
  181.                                                  '
  182. PRINT "Shape number < 1 -"; MaxRec%; ">  : ";    'Get which record...
  183.                                                  '
  184. INPUT RNum%                                      '
  185.                                                  '
  186. IF RNum% <= 0 THEN                               '
  187.    PRINT "Bad shape number.  Redo..."            '
  188.    GOTO TryAgain                                 '
  189. ELSEIF RNum > MaxRec% THEN                       'Passed end of file.
  190.    PRINT "Bad shape number.  Redo..."            '
  191.    GOTO TryAgain                                 '
  192. END IF                                           '
  193.                                                  '
  194. RNum% = RNum% + 1                                'Skip over header.
  195.                                                  '
  196. END SUB                                          '
  197.  
  198. '
  199. '****************************************************************************
  200. '*                                                                          *
  201. '* Read the shape DATA into SHPDAT$, then tell the Changepointer            *
  202. '* routine to change the mouse cursor to the new shape.                     *
  203. '*                                                                          *
  204. '****************************************************************************
  205. '
  206. SUB ReadData
  207.  
  208. '============================================================================
  209.  
  210. READ HotX%, HotY%                                'First 2 statements are
  211.                                                  'X and Y hotspots.
  212. FOR xdata = 1 TO 32                              '
  213.    READ SHPdata%                                 '
  214.    SHPDAT$ = SHPDAT$ + MKI$(SHPdata%)            'Build data string.
  215. NEXT xdata                                       '
  216.                                                  '
  217. CALL ChangePointer(SHPDAT$, HotX%, HotY%)        'Change it.
  218.                                                  '
  219. '============================================================================
  220.  
  221. END SUB
  222.  
  223. SUB Target
  224.  
  225. LINE (15, 16)-(615, 465), 15, BF
  226.                                                
  227. Colr% = 0
  228. FOR Size% = 220 TO 20 STEP -20
  229.  
  230.    Colr% = Colr% + 1
  231.    CIRCLE (320, 240), Size%, Colr%
  232.    PAINT (320, 240), Colr%, Colr%
  233.  
  234. NEXT
  235.  
  236. END SUB
  237.  
  238.